import requests
import json
import getDetailInfo
import downFile

# 目标URL
menuUrl = "https://ecp.sgcc.com.cn/ecp2.0/ecpwcmcore/index/noteList"

# 初始化参数
base_data = {
    "size": 20,
    "firstPageMenuId": "2018060501171107",
    "orgId": "",
    "key": "湖北",
    "year": "",
    "orgName": ""
}

# 设置请求头，模拟浏览器
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
    'Content-Type': 'application/json'
}

# 存储所有数据
all_data = []
total_count = 0
# 循环发送请求，从1到100
for index in range(1, 3):
    # 动态设置index
    data = base_data.copy()
    data["index"] = index

    # 发送POST请求
    response = requests.post(menuUrl, json=data, headers=headers)

    # 检查请求是否成功
    if response.status_code == 200:
        # 将响应内容转换成JSON对象
        response_data = response.json()

        # 提取所需数据
        if 'resultValue' in response_data:
            data_list = response_data.get('resultValue').get('noteList')
            total_count=total_count+len(data_list)
            for item in data_list:
                if 'title' in item and '物资' in item['title']:
                    all_data.append(item)
        else:
            print(f"No data found in the response for index {index}.")
    else:
        print(f"Failed to send POST request for index {index}: {response.status_code}")

# 输出所有数据
#print(json.dumps(all_data, indent=2, ensure_ascii=False))

print(f"本次统计数据总数:{total_count} 筛选符合[湖北,物资]条件的数据总数:{len(all_data)}")
getDetailInfo.process_detail(all_data)